import grails.util.BuildSettings
import grails.util.Environment
import org.springframework.boot.logging.logback.ColorConverter
import org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter

import java.nio.charset.Charset

conversionRule 'clr', ColorConverter
conversionRule 'wex', WhitespaceThrowableProxyConverter

// See http://logback.qos.ch/manual/groovy.html for details on configuration
appender('STDOUT', ConsoleAppender) {
	encoder(PatternLayoutEncoder) {
		charset = Charset.forName('UTF-8')
		// 记录日志的模式
		pattern = "%yellow(%d{HH:mm:ss.SSS}) [%mdc{x}] [%relative] [%thread] [%highlight(%-5level) %cyan(%logger{30})] - %msg%n"
//        pattern =
//                '%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} ' + // Date
//                        '%clr(%5p) ' + // Log level
//                        '%clr(---){faint} %clr([%15.15t]){faint} ' + // Thread
//                        '%clr(%-40.40logger{39}){cyan} %clr(:){faint} ' + // Logger
//                        '%m%n%wex' // Message
	}
}

def targetDir = BuildSettings.TARGET_DIR
if (Environment.isDevelopmentMode() && targetDir != null) {
	appender("FULL_STACKTRACE", FileAppender) {
		file = "${targetDir}/stacktrace.log"
		append = true
		encoder(PatternLayoutEncoder) {
			pattern = "%level %logger - %msg%n"
		}
	}
	logger("StackTrace", ERROR, ['FULL_STACKTRACE'], false)
}
List appenders = ['STDOUT']
root(ERROR, ['STDOUT'])
// 记录日志级别，这个地方设置了日志的输出级别
logger('grails.app', all, appenders, false)
// 输出启动耗时
logger('promotioncalc.Application', DEBUG, appenders, false)
logger("promotioncalc.PromotionEmployeeController",DEBUG,appenders,false)

// Hibernate
logger('org.hibernate', ERROR, appenders, false)
logger('org.hibernate.tool.hbm2ddl.SchemaExport', DEBUG, appenders, false)
logger('org.hibernate.tool.hbm2ddl.SchemaUpdate', DEBUG, appenders, false)          // 打开用于查看数据Schema的创建过程